package com.xxx.meter.ui.patrol.machine.back;

import android.app.Activity;
import android.view.View;
import android.widget.EditText;

import com.xxx.meter.R;
import com.xxx.meter.base.BaseActivity;
import com.xxx.meter.base.BaseDialog;
import com.xxx.meter.model.data.meter.MeterUtil;
import com.xxx.meter.model.data.patrol.PatrolUtil;
import com.xxx.meter.model.utils.KeyBoardUtil;
import com.xxx.meter.model.utils.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class PatrolMachineBackWindow extends BaseDialog {

    private Callback callback;
    private Activity activity;

    @BindView(R.id.window_patrol_back_edit)
    EditText mBackEdit;

    public static PatrolMachineBackWindow getInstance(BaseActivity activity, Callback callback) {
        return new PatrolMachineBackWindow(activity, callback);
    }

    private PatrolMachineBackWindow(Activity context, Callback callback) {
        super(context);
        this.activity = context;
        this.callback = callback;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.window_patrol_back;
    }

    @Override
    protected void initData() {
        mBackEdit.setText(PatrolUtil.getSubmitData());

        KeyBoardUtil.openKeyBord(activity, mBackEdit);
        KeyBoardUtil.setFilters(mBackEdit);
    }

    @OnClick({R.id.window_patrol_back_btn, R.id.window_patrol_back_finish})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.window_patrol_back_btn:
                String string = mBackEdit.getText().toString();
                if (string.isEmpty()) {
                    ToastUtil.showToast("内容不能为空");
                    return;
                }
                if (callback != null) callback.callback(string);
                dismiss();
                break;
            case R.id.window_patrol_back_finish:
                dismiss();
                break;
        }
    }

    @Override
    public void dismiss() {
        KeyBoardUtil.closeKeyBord(getContext(), mBackEdit);
        super.dismiss();
    }

    public interface Callback {

        void callback(String data);

    }
}
